# -- coding: utf-8 --

"""
批量检查内网服务器对应的漏洞版本
"""
import socket
import os
import sys


def retbanner(ip, port):
    try:
        socket.setdefaulttimeout(2)
        s = socket.socket()
        s.connect((ip, port))
        banner = s.recv(1024)
        return banner
    except:
        return


def checkVlus(banner,filename):
    f = open(filename, 'r')
    for line in f.readline():
        if line.strip('\n') in banner:
            print('[+]Server is vulnerable :' + banner.strip('\n'))


def main():
    if len(sys.argv) == 2:
        filename = sys.argv[1]
        if not os.path.isfile((filename)):
            print('[+]' + filename + 'does not exist.')
            exit(0)
        if not os.access(filename,os.R_OK):
            print('[+]' + filename + 'access denied.')
            exit(0)
        else:
            print('[-] Usage :'+ str(sys.argv[0]) + '<vuln filename>')
            exit(0)

            port_list = [21,22,25,80,110,443]
            for i in range(1, 255):
                ip = '192.168.0' + str(i)
                for port in port_list:
                    banner = retbanner(ip, port)
                    if banner:
                        print('[+]' + ip + ':' + banner)
                        checkVlus(banner,filename)


if __name__ == '__main__':
    main()
